package cn.com.egova.demoapplication;

import android.animation.ValueAnimator;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import cn.com.egova.demoapplication.base.BaseActivity;

public class ValueAnimatorActivity extends BaseActivity {

    @InjectView(R.id.btn)
    Button btn;
    @InjectView(R.id.tv)
    TextView tv;
    @InjectView(R.id.tv2)
    TextView tv2;
    private ValueAnimator v1;
    private ValueAnimator v2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_value_animator);
        ButterKnife.inject(this);

        initAnimator();
    }

    @Override
    public boolean isBackIconVisible() {
        return true;
    }

    @OnClick(R.id.btn)
    public void onClick() {
        v1.start();
        v2.start();
    }


    private void initAnimator(){
        v1 = ValueAnimator.ofFloat(0f,1f);
        v1.setDuration(3000);
        v2 = ValueAnimator.ofInt(0,60);
        v2.setDuration(3000);

        v1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                tv.setText(value+"");
            }
        });

        v2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int value = (int) animation.getAnimatedValue();
                tv2.setText(value+"");
            }
        });
    }
}
